home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / C for beginners.adf / source / draw.c < prev    next >
C/C++ Source or Header  |  1978-01-17  |  4KB  |  166 lines

  1. /* draw1.c 25.4.3  */
  2. /* From Amiga C for Beginners */
  3. /* by Abacus                  */
  4.  
  5. #include <exec/types.h>
  6. #include <intuition/intuition.h>
  7.  
  8. extern LONG OpenLibrary();
  9. extern struct Screen *OpenScreen();
  10. extern struct Window *OpenWindow();
  11.  
  12. struct IntuitionBase *IntuitionBase;
  13. struct GfxBase *GfxBase;
  14.  
  15. #define INTUITION_REV 0
  16. #define GRAPHICS_REV 0
  17.  
  18. struct TextAttr Font =
  19. {
  20.    "topaz.font",
  21.    TOPAZ_EIGHTY,
  22.    FS_NORMAL,
  23.    FPF_ROMFONT,
  24. };
  25.  
  26. UBYTE screentitle[81];
  27.  
  28.  
  29. struct NewScreen NewScreen =
  30. {
  31.    0,0,
  32.    640, /* Width */
  33.    200, /* Height; PAL version-may change 200 to 256 */
  34.    2,   /* 3 bitplanes = 8 colors */
  35.    2,3, /* another color combination */
  36.    HIRES,
  37.    CUSTOMSCREEN,
  38.    &Font,
  39.    screentitle,
  40.    NULL,
  41.    NULL,
  42. };
  43.  
  44. struct NewWindow NewWindow =
  45. {
  46.    20, 20,   /* X and Y Position */
  47.    400, 180,  /* Width, Height */
  48.    0,1,     /* Colors (0 - 7) */
  49.    CLOSEWINDOW,
  50.    WINDOWCLOSE | SMART_REFRESH | ACTIVATE | WINDOWSIZING |
  51.       SIZEBRIGHT | WINDOWDRAG | WINDOWDEPTH,
  52.    NULL,
  53.    NULL,
  54.    "* My window *",
  55.    NULL,
  56.    NULL,
  57.    190, 20,
  58.    640, 200, /* in PAL systems may change 200 to 256 */
  59.    CUSTOMSCREEN
  60. };
  61.  
  62.  
  63. main(argc,argv)
  64. int argc;
  65. char *argv[];
  66. {
  67.    struct Screen *Screen;
  68.    struct Window *Window;
  69.    register char s[81];
  70.    int color = 4;
  71.    register int x, y, xalt, yalt;
  72.  
  73.    if((IntuitionBase = (struct IntuitionBase *)
  74.      OpenLibrary("intuition.library", INTUITION_REV))
  75.      == NULL)
  76.      exit(FALSE);
  77.  
  78.    if ((GfxBase = (struct GfxBase *)
  79.       OpenLibrary("graphics.library",GRAPHICS_REV))
  80.       == NULL)
  81.       exit(FALSE);
  82.  
  83.    if (argc != 4)
  84.       {
  85.          printf("Error in arguments\n");
  86.          printf("X-Res Y-Res Bitplanes\n");
  87.       }
  88.    else
  89.       {
  90.          NewScreen.Width   =  atoi(argv[1]);
  91.          NewScreen.Height  =  atoi(argv[2]);
  92.          NewScreen.Depth   =  atoi(argv[3]);
  93.          if(NewScreen.Depth > 4 || NewScreen.Depth < 1)
  94.             NewScreen.Depth = 2;
  95.          color = 1 << NewScreen.Depth;
  96.          NewScreen.DetailPen  =  color - 1;
  97.          NewScreen.BlockPen   =  color - 2;
  98.       }
  99.  
  100.  
  101.  
  102.    sprintf(screentitle,"This screen has %d colors",
  103.             color);
  104.  
  105.     if ( (Screen = OpenScreen(&NewScreen) ) == NULL)
  106.       exit(FALSE);
  107.  
  108.    NewWindow.Screen = Screen; /* Do not forget! */
  109.  
  110.    if (argc == 4)
  111.       {
  112.          NewWindow.Width      =  Screen->Width/2;
  113.          NewWindow.Height     =  Screen->Height/3;
  114.          NewWindow.MinWidth   =  Screen->Width/3;
  115.          NewWindow.MinHeight  =  Screen->Height/5;
  116.          NewWindow.MaxWidth   =  Screen->Width;
  117.          NewWindow.MaxHeight  =  Screen->Height;
  118.       }
  119.  
  120.  
  121.    if( (Window = OpenWindow(&NewWindow) ) == NULL)
  122.      exit(FALSE);
  123.  
  124.   text(Window,"Hello there!",20,20);
  125.  
  126.    /* Initialize with start values */
  127.    Move(Window->RPort, xalt = Window->MouseX,
  128.            yalt = Window->MouseY);
  129.  
  130.    /* Drawing starts here until upper or*/
  131.    /* left  border is reached */
  132.    while( (x = Window->MouseX) > 0 &&
  133.             (y = Window->MouseY) > 0)
  134.       {
  135.          sprintf(s,"X = %3d, Y =%3d", x , y);
  136.          text(Window, s, 150, 7);
  137.          Move(Window->RPort, xalt, yalt);
  138.          Draw(Window->RPort, xalt = x, yalt = y);
  139.       }
  140.  
  141.    text(Window, "Please click the close gadget", 20, 20);
  142.  
  143.  
  144.    /* Wait for Close-Gadget */
  145.    Wait(1 << Window->UserPort->mp_SigBit);
  146.  
  147.    CloseWindow(Window);
  148.     /* Close everything in sequence*/
  149.    CloseScreen(Screen);
  150.    CloseLibrary(GfxBase);
  151.    CloseLibrary(IntuitionBase);
  152.    exit(TRUE);
  153. }
  154.  
  155.  
  156.  
  157. text(w_ptr, s, x, y)
  158. struct Window *w_ptr;
  159. char *s;
  160. int x, y;
  161. {
  162.    Move(w_ptr->RPort, x, y);
  163.    Text(w_ptr->RPort, s, strlen(s));
  164. }
  165.  
  166.